package com.kate.mall.member.controller;

import com.kate.mall.common.utils.PageUtils;
import com.kate.mall.common.utils.R;
import com.kate.mall.log.annotation.LogAnnotation;
import com.kate.mall.member.entity.MemberEntity;
import com.kate.mall.member.service.MemberService;
import com.kate.mall.member.vo.UserForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 会员表 
 *
 * @author kate-chan
 * @email ccsu_loader@163.com
 * @date 2021-10-08 16:10:48
 */
@Api(tags = "MemberController", description = "会员表 服务")
@RestController
@RequestMapping("user/member")

public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("user:member:list")
    @ApiOperation("获取所有会员表 信息")
    @LogAnnotation(module = "member-center")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("user:member:info")
    @ApiOperation("获取指定id的会员表 详情")
    public R info(@PathVariable("id") Integer id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("添加会员表 信息")
    //@RequiresPermissions("user:member:save")
    public R save(@RequestBody  @Valid UserForm userForm){
		memberService.save(userForm);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation("更新指定id会员表 信息")
    //@RequiresPermissions("user:member:update")
    public R update(@RequestBody  MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除指定id会员表 信息")
    //@RequiresPermissions("user:member:delete")
    public R delete(@RequestBody Integer[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
